package view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JPanel;

public class SideBar extends JPanel{
	private static final long serialVersionUID = 1L;

	private int bar_width   = 200;
	private int child_ident = 20;
	private int item_width  = 190;
	private int item_height = 30;
	
	public SideBar(){
		setPreferredSize(new Dimension(bar_width, bar_width));
		setLayout(new FlowLayout(FlowLayout.RIGHT));
		setBackground(Color.CYAN);
		
		ParentTask qlp = new ParentTask("Quản lí phòng"); 
		add(qlp);
		final ChildTask them_phong = new ChildTask("Thêm phòng");
		final ChildTask tim_phong = new ChildTask("Tìm phòng");
		final ChildTask thong_ke_phong = new ChildTask("Thống kê phòng");
		add(them_phong);
		add(tim_phong);
		add(thong_ke_phong);
		
		add(new ParentTask("Quản lí  nhân viên"));
		add(new ChildTask("Thêm nhân viên"));
		add(new ChildTask("Tìm nhân viên"));
		add(new ParentTask("Quản lí dịch vụ"));
		add(new ChildTask("Thêm dịch vụ"));
		add(new ChildTask("Tìm dịch vụ"));
		
		qlp.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				// TODO Auto-generated method stub
				if (them_phong.isVisible()){
					them_phong.setVisible(false);
					tim_phong.setVisible(false);
					thong_ke_phong.setVisible(false);
				}else {
					tim_phong.setVisible(true);
					thong_ke_phong.setVisible(true);
					them_phong.setVisible(true);
				}
			}
		});
	}
	
	class ParentTask extends JButton{
		private static final long serialVersionUID = 1L;
		
		public ParentTask(String title){
			super(title);
			setPreferredSize(new Dimension(item_width, 30));
			setHorizontalAlignment(JButton.LEFT);
		}
	}
	
	class ChildTask extends JButton{
		private static final long serialVersionUID = 1L;

		public ChildTask(String title){
			super(title);
			setPreferredSize(new Dimension(item_width-child_ident, item_height));
			setHorizontalAlignment(JButton.LEFT);
			setBackground(new Color(0, 0, 0, 0));
			setForeground(Color.BLACK);
			addMouseMotionListener(new MouseHandlerForButton());
			addMouseListener(new MouseHandlerForButton());
		}
	}
	
	class MouseHandlerForButton extends MouseAdapter{
		
		public MouseHandlerForButton(){
			
		}
		public void mouseEntered(MouseEvent event){
			JButton bt = (JButton) event.getSource();
			bt.setBackground(Color.BLUE);
			bt.setForeground(Color.WHITE);
		}
		public void mouseExited(MouseEvent event){
			JButton bt = (JButton) event.getSource();
			bt.setBackground(new Color(0, 0, 0,0));
			bt.setForeground(Color.BLACK);
		}
	}
	
}
